package com.example.mybatisplus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.model.domain.HOrder;
import com.example.mybatisplus.mapper.HOrderMapper;
import com.example.mybatisplus.model.dto.PageDto;
import com.example.mybatisplus.service.HOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author yfy
 * @since 2021-12-30
 */
@Service
public class HOrderServiceImpl extends ServiceImpl<HOrderMapper, HOrder> implements HOrderService {
    @Autowired
    private HOrderMapper orderMapper;

    @Override
    public Page<HOrder> listByPage(PageDto page,HOrder order) {
        Page<HOrder> page1 = new Page<>(page.getPageNo(), page.getPageSize());
        QueryWrapper<HOrder> wrapper =new QueryWrapper<>();
        if (order.getBack()!=null){
            wrapper.lambda().like(HOrder::getBack,order.getBack());
        }
        if (order.getInNum()!=null){
            wrapper.lambda().like(HOrder::getInNum,order.getInNum());
        }
        if (order.getInState()!=null){
            wrapper.lambda().like(HOrder::getInState,order.getInState());
        }
        if (order.getOState()!=null){
            wrapper.lambda().like(HOrder::getOState,order.getOState());
        }
        if (order.getOutState()!=null){
            wrapper.lambda().like(HOrder::getOutState,order.getOutState());
        }
        if (order.getPrice()!=null){
            wrapper.lambda().like(HOrder::getPrice,order.getPrice());
        }
        if (order.getPState()!=null){
            wrapper.lambda().like(HOrder::getPState,order.getPState());
        }
        if (order.getUsername()!=null){
            wrapper.lambda().like(HOrder::getUsername,order.getUsername());
        }
        page1 = orderMapper.selectPage(page1, wrapper);
        return page1;
    }
//    public Page<HOrder> getOrderWithUser(PageDto page,HOrder order) {
//        return orderMapper.getOrderWithUser(new Page<>(page.getPageNo(),page.getPageSize()),order);
//    }
}
